/*
 * Copyright 2008 Wink Saville
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.saville.testhmc;

import com.saville.msgcomp.*;
import com.saville.mc.*;
import com.saville.testclient.*;

public class Test {
    
    /**
     * Test it
     * 
     * @param Debug one bit for each test
     */
    public static void doThem(int Debug, int count, boolean noisy) {
        
        IMcMgr mcMgr = McMgr.getInstance();

        if ((Debug & 0x1) != 0) {
            new TestDeferredMsgs("TestDeferredMsgs");
        }

        if ((Debug & 0x2) != 0) {
            /* Create the server */
            new TestUnhandledMsgs("TestUnhandledMsgs");

            /* Send a few messages to server */
            int dstId = mcMgr.lookup("TestUnhandledMsgs");
            for (int i = 0; i < 3; i++) {
                /*
                 * Send a message that doesn't require a reply, because this
                 * Activity isn't an Mc.
                 */
                Msg msg = mcMgr.getMsg();
                msg.dstId = dstId;
                msg.guid = 0;
                msg.cmd = 0;
                mcMgr.sendMsg(msg);
            }
        }

        if ((Debug & 0x4) != 0)
            new TestHmcServer("TestHmcServer");

        if ((Debug & 0x8) != 0) {
            if ((Debug & 0x4) == 0)
                new TestHmcServer("TestHmcServer");

            for (int i = 0; i < 2; i++) {
                String clientName = "TestClient" + i;
                new TestClient(clientName);
                Msg msg = mcMgr.getMsg();
                msg.dstId = mcMgr.lookup(clientName);
                msg.guid = 0;
                msg.cmd = 0;
                msg.arg1 = count; // Count
                msg.arg2 = mcMgr.lookup("TestHmcServer"); // ServerDstId
                msg.arg3 = noisy ? McConst.NOISY : 0; // ServerCmd

                mcMgr.sendMsg(msg);
            }
        }
    }
}
